using System.Drawing;
using System.Drawing.Drawing2D;

namespace DrawTools.Editor.CanvasFigures
{
  /// <summary>
  ///   Ellipse graphic object
  /// </summary>
  public class CanvasEllipse : CanvasRectangle
  {
    public CanvasEllipse() : this(0, 0, 1, 1) {}

    public CanvasEllipse(int x, int y, int width, int height)
    {
      Rectangle = new Rectangle(x, y, width, height);
    }

    public override void Draw(Graphics graphics)
    {
      using (var pen = CreateBorderPen())
      using (var brush = CreateBackBrush())
      {
        var rect = GetNormalizedRectangle(Rectangle);

        if (LineType != LineType.None || BackgroundOpacity > 0)
        {
          var path = new GraphicsPath();
          path.AddEllipse(rect);
          path.CloseFigure();

          DrawFuzzyPath(graphics, path, BorderColor);
        }

        graphics.FillEllipse(brush, rect);

        if (LineType != LineType.None)
        {
          graphics.DrawEllipse(pen, rect);
        }
      }
    }
  }
}